package controls{
	import mx.controls.Menu;
	import mx.controls.PopUpButton;
	import mx.events.MenuEvent;
	
	[Event(name="startTaskMenuClick", type="controls.TaskStatusChartEvent")]
	[Event(name="stopTaskMenuClick", type="controls.TaskStatusChartEvent")]
	
	
	public class TaskStatusChartNode extends PopUpButton{
		
		private var dp:Array = [
				{label:"启动", value:TaskStatusChartEvent.START_TASK_MENU_CLICK},
				{label:"停止", value:TaskStatusChartEvent.STOP_TASK_MENU_CLICK}
			];
			
		private var startDP:Array = [
				{label:"启动", value:TaskStatusChartEvent.START_TASK_MENU_CLICK},
			];
		private var stopDP:Array = [
				{label:"停止", value:TaskStatusChartEvent.STOP_TASK_MENU_CLICK}
			];
			
		private var menu:Menu;
		
		[Embed('assets/zoomin.png')]
		private var startIcon:Class;
		
		[Embed('assets/zoomout.png')]
		private var stopIcon:Class;
		
		public function TaskStatusChartNode(){
			menu = new Menu();
			menu.dataProvider = dp;
			menu.addEventListener(MenuEvent.ITEM_CLICK, onMenuItemClick);
			this.popUp = menu;
		}
		
		private function onMenuItemClick(event:MenuEvent):void{
			//trace("[TaskStatusChartNode onMenuItemClick] event =" +  event );
			//trace("[TaskStatusChartNode onMenuItemClick] menu.selectedItem =" +  menu.selectedItem );
			
			var operation:String = "";
			try{
				operation  = menu.selectedItem.value;
			}catch(e:Error){
				trace("ERROR [TaskStatusChartNode onMenuClick] e =" + e);
				//operation  = menu.dataProvider[menu.selectedIndex].value;
			}
			//trace("[TaskStatusChartNode onMenuItemClick] operation =" +  operation );
			if(willTrigger(operation)){
				dispatchEvent(new TaskStatusChartEvent(operation, this));
			}
		} 
		
		override public function set data(value:Object):void{
			super.data = value;
			//trace("[TaskStatusChartNode set data] value =" +  value );
			if(value.taskstatus == 0){
				menu.dataProvider = startDP;
				this.setStyle("icon", stopIcon);
			}else{
				menu.dataProvider = stopDP;
				this.setStyle("icon", startIcon);
			} 
			invalidateDisplayList();
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
		}
		
	}
}